package remote.controllers;

import remote.constants.IRequestTypes;
import remote.constants.IWMPConstants;
import remote.activities.FileBrowserActivity;
import remote.activities.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;

public class WMPController extends BaseController implements OnClickListener, OnTouchListener
{
	public WMPController(Activity activity)
	{
		super(activity);
	}

	@Override
	public void onClick(View v)
	{
		switch(v.getId())
		{
			case R.drawable.ic_volume_off :
				_client.send(IRequestTypes.WMP_REMOTE, IWMPConstants.VOLUME_MUTE);
				break;
			case R.drawable.ic_volume_low :
				_client.send(IRequestTypes.WMP_REMOTE, IWMPConstants.VOLUME_DOWN);
				break;
			case R.drawable.ic_volume :
				_client.send(IRequestTypes.WMP_REMOTE, IWMPConstants.VOLUME_UP);
				break;
			case R.drawable.ic_media_previous :
				_client.send(IRequestTypes.WMP_REMOTE, IWMPConstants.MEDIA_PREVIOUS_TRACK);
				break;
			case R.drawable.ic_media_play_pause :
				_client.send(IRequestTypes.WMP_REMOTE, IWMPConstants.MEDIA_PLAY_PAUSE);
				break;
			case R.drawable.ic_media_stop :
				_client.send(IRequestTypes.WMP_REMOTE, IWMPConstants.MEDIA_STOP);
				break;
			case R.drawable.ic_media_next :
				_client.send(IRequestTypes.WMP_REMOTE, IWMPConstants.MEDIA_NEXT_TRACK);
				break;
			case R.id.media_controller_imgFolder :
				String response = _client.send(IRequestTypes.FILE_BROWSER, "");
				Intent intent = new Intent(_activity, FileBrowserActivity.class);
				Bundle bundle = new Bundle();
				
				bundle.putString(FileBrowserController.FILE_BROWSER_KEY, _client.getResponseData(response));
				intent.putExtras(bundle);
				_activity.startActivity(intent);
				_activity.finish();
				
				break;
		}
	}
	
	@Override
	public boolean onTouch(View view, MotionEvent event)
	{
		boolean isConsumed = false;
		
		if(event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP)
		{
			isConsumed = true;
			
			switch(view.getId())
			{
				case R.drawable.ic_media_rew :
					_client.send(IRequestTypes.WMP_REMOTE, IWMPConstants.MEDIA_REWIND);
					break;
				case R.drawable.ic_media_ff :
					_client.send(IRequestTypes.WMP_REMOTE, IWMPConstants.MEDIA_FAST_FORWARD);
					break;
				default :
					isConsumed = false;
					break;
			}
		}
		
		return isConsumed;
	}
}
